<?php
namespace Index\Controller;
use Think\Controller;
class UserController extends Controller {
    public function index(){

       $this->display();

    }	
    public function set()
    {
    	$data = M('user')->find($_SESSION['uid']);
    	$this->assign('user',$data);
    	$this->display();
    }
    public function msg()
    {
    	$this->display();
    }


    	//我的资料
		public function  amendadd()
		{
			$data=I('post.');

			$id=$_SESSION['uid'];
			// var_dump(M('user')->where("id='$id'")->save($data));exit;
			if (M('user')->where("id='$id'")->save($data)) {
				 
				$_SESSION['nickname']=$data['nickname'];
				$_SESSION['city']=$data['city'];
				$_SESSION['sign']=$data['sign'];
				 Reajax(0,"修改完成");

			}else{
				Reajax(1,"修改失败");
			}
		}
		//修改密码
		public function amendpass()
		{
			$data=I('post.');

			$id=$_SESSION['uid'];
			if ($data['pass']==$data['repass']) {

				$data['password']=md5($data['pass']);

				if (M('user')->where("id='$id'")->save($data)) {
					
					Reajax(0,"修改密码成功");
				}else{
					Reajax(1,"修改密码失败");
				}
			}else{
				Reajax(1,"两次密码不一样");
			}
	
		}

		public function upload()
		{
			    $upload = new \Think\Upload();// 实例化上传类
			    $upload->maxSize   =     3145728 ;// 设置附件上传大小
			    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
			    $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
			    $upload->savePath  =     ''; // 设置附件上传（子）目录
			    // 上传文件 
			    $info   =   $upload->upload();
			   
			    if(!$info) {// 上传错误提示错误信息
			        $this->error($upload->getError());
			    }else{// 上传成功
			       
			    	$info=current($info);

			        $facepath="/Uploads/".$info['savepath'].$info['savename'];
			        $data['face']=$facepath;
			        // var_dump($facepath);
			        $data['id']=$_SESSION['uid'];
			        $_SESSION['face']=$data['face'];
			        M('user')->save($data);
			        echo $data['face'];
			    }
		}






}
?>